import uniCrazyRouter, {
  beforeEach,
  afterEach,
  onError,
} from "uni-crazy-router";

// 开放给main.js
export function setupRouter(app) {
  // 接收vue3的实例
  app.use(uniCrazyRouter);
  // eslint-disable-next-line no-unused-vars
  beforeEach(async (to, from, next) => {
    next();
  });

  afterEach((to, from) => {
    const bpList = [
      "pages/chatDemo/chatList",
      "pages/chatDemo/createAgent",
      "pages/chatDemo/user",
    ];
    if (bpList.includes(to.url)) {
      const bpFrom = from.url ? `h5healthmall/${from.url}` : "";
      const bpTo = `h5healthmall/${to.url}`;
      uni.setStorageSync("bpTo", bpTo);
    }
  });

  // eslint-disable-next-line no-unused-vars
  onError((to, from) => {
    uni.showToast({
      title: `${to.url} 不存在`,
      icon: "none",
    });
  });
}
